﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.CMS263.PO;
using Com.CMS263.BLL;
using Com.CMS263.Util;
using System.IO;

namespace Com.CMS263.Web.manage.MarryInfo
{
    public partial class MarryImageEdit : System.Web.UI.Page
    {
        public int page;
        public MarryImage mi = new MarryImage();
        MarryImageBLL miBll = new MarryImageBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = int.Parse(Request["id"]);
            page= int.Parse(Request["page"]);
            mi = (MarryImage)miBll.FindModelById("MarryImage", id);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            page = int.Parse(Request["page"]);
            string strDay = DateTime.Now.ToString("yyyy-MM-dd");
            string savePath = Server.MapPath("/ArtUpFile/" + strDay);
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            string FilePath = strDay + "/" + UpLoadFileUtil.UpLoadFile(Request.Files["FilePath"], savePath);

            int id = int.Parse(Request["id"]);
            mi = (MarryImage)miBll.FindModelById("MarryImage", id);
            mi.Title = StringUtil.checkStr(Request["Title"]);
            mi.ProductId = int.Parse(Request["ProductId"]);
            mi.ProductTitle = Request["ProductTitle"];
            mi.SortId = int.Parse(string.IsNullOrEmpty(Request["SortId"]) ? "0" : Request["SortId"]);
            mi.FilePath = FilePath;
            miBll.entity = mi;
            if (miBll.UpDate())
            {
                StringUtil.Alert("更新成功！", "MarryImageList.aspx?page="+page+"&&id="+mi.ProductId);
            }
            else
            {
                StringUtil.Alert("更新失败，请重新操作！", "-1");

            }


        }
    }
}
